package member

import (
	"context"
	"stormragetech/dawn/model"
)

// UserRPC RPC统一接口
type UserRPC int

// SignupRPCServ RPC注册接口
func (t *UserRPC) SignupRPCServ(ctx context.Context, args *model.SignupArgs, reply *model.SignupReply) error {

	err := SignupHandle(args.Username, args.Password, args.Realname, args.DeptID)
	if err != nil {
		*reply = model.SignupReply{Code: "9999", Msg: err.Error(), Data: ""}
		return nil
	}

	*reply = model.SignupReply{Code: "0000", Msg: "注册成功", Data: ""}
	return nil
}

// LoginRPCServ RPC登录接口
func (t *UserRPC) LoginRPCServ(ctx context.Context, args *model.LoginArgs, reply *model.LoginReply) error {
	token, err := LoginHandle(args.Username, args.Password)
	if err != nil {
		*reply = model.LoginReply{Code: "9999", Msg: err.Error(), Data: ""}
		return nil
	}

	*reply = model.LoginReply{Code: "0000", Msg: "登录成功", Data: token}
	return nil
}
